#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n;
int a[N],c[N];
int vis[N],ans;//1 red 0 blue
void dfs(int step){
	if(step==n+1){
		int sub=0;
		for(int i=1;i<=n;i++)
			sub+=c[i];
		ans=max(ans,sub);
		return;
	}
	bool flag;
	vis[step]=1; flag=false;
	for(int i=step-1;i>=1;i--)
		if(vis[i]==vis[step]){
			flag=true;
			if(a[step]==a[i])
				c[step]=a[step];
			else
				c[step]=0;
			break;
		}
	if(!flag)
		c[step]=0;
	dfs(step+1);vis[step]=-1;
	vis[step]=0; flag=false;
	for(int i=step-1;i>=1;i--)
		if(vis[i]==vis[step]){
			flag=true;
			if(a[step]==a[i])
				c[step]=a[step];
			else
				c[step]=0;
			break;
		}
	if(!flag)
		c[step]=0;
	dfs(step+1);vis[step]=-1;
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--){
		memset(vis,-1,sizeof vis);
		ans=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		vis[1]=1;
		dfs(2);
		printf("%d\n",ans);
	}
	return 0;
}

